var g_canvas, g_context, g_winReq, g_mouse, g_star1, g_star2, g_star3;

function starRotation( star, isEvenStar )
{
    var dx = g_mouse.x - star.x;
    var dy = g_mouse.y - star.y;
    if ( isEvenStar )
    {
        star.rotation = Math.atan2( dx, dy ); 
    }
    else
    {
        star.rotation = Math.atan2( dy, dx ); 
    }
}

function drawFrame() 
{
    g_winReq( drawFrame, g_canvas );
    g_context.clearRect( 0, 0, g_canvas.width, g_canvas.height );
    g_canvas.onmousemove = mouseMove;   
    starRotation( g_star1, false );
    starRotation( g_star2, true );
    starRotation( g_star3, false );
    g_star1.draw( g_context, 0, 160, 36, 52, 60, -20, 100, -136, -64 );
    g_star2.draw( g_context, 0, 80, 18, 26, 30, -10, 50, -68, -32 );
    g_star3.draw( g_context, 0, 40, 9, 13, 15, -5, 25, -34, -16 );
}

function mouseMove()
{
    g_mouse = captureMouse();     
}

function onloadHandler()
{
    g_canvas = document.getElementById('canvas');
    g_context = g_canvas.getContext( '2d' );
    g_winReq = winRequestAnimFrame(); 
    
    g_mouse = captureMouse();   
    g_star1 = new Star( 200, 200, "#fac800", 0, 200, 1 );
    g_star2 = new Star( 200, 200, "#c94197", 0, 200, 1 );
    g_star3 = new Star( 200, 200, "#007fff", 0, 200, 1 );

    drawFrame();
}

window.onload = onloadHandler;    